<template>
	<van-pull-refresh v-model="isLoading" @refresh="onRefresh" :disabled="refDisabled">
	<div class="content" ref="pageInfo">
		<div class="tips flex2">
			<div class="flex1" v-if='userInfo.pid' @click="showPicker=true">
				<div>就诊人 <span>{{userInfo.pat_name||''}}（{{userInfo.phno||''}}）</span></div>
				<img src="@/assets/img/index/more_w.png" alt="">
			</div>
			<div class="flex1" v-else @click="toPageLink('/addVisitor')">
				添加就诊人
				<img src="@/assets/img/index/more_w.png" alt="">
			</div>
		</div>
		<back-img></back-img>
		<div class="registerList">
			<div class="registerList-i pr" @click="toNumShow(v)" v-for="(v,i) in dataList" :key='i'>
				<div class="flex1" style="margin-bottom: 9px;">
					<div class="registerList-i-name">{{v.dept_name}}门诊-{{v.doctor_name}}</div>
					<!-- "exe_status": "就诊状态|0-等待接诊,1-完成就诊,2-正在就诊,-1标记为不就诊", -->
					<!-- pay_status": "支付状态|0-待支付;1-已支付;2-已退费", -->
					<div class="registerList-i-btn" :class="v.exe_status == '-1'||v.exe_status == 1?'gary_btn':''">
					   {{getStatusText(v)}}
					</div>
				</div>
				<div class="registerList-i-t">{{v.doctor_name}}<span>山西天慈医院</span></div>
				<div>
					{{v.visit_time}} 
					<!-- 第 <span class="c_1977FD">{{v.ser_num}}</span> 号 -->
				</div>
				<img class="registerList-i-more pa" src="@/assets/img/index/more_g.png" alt="">
			</div>
		</div>
		<div class="noData" v-if='dataList.length<=0'>
			<img class="noData-img" src="@/assets/img/index/nodata.png" alt="">
			<div class="noData-text">未查到数据</div>
		</div>
		<van-popup v-model:show="showPicker" round position="bottom">
		  <van-picker
		    :show-toolbar='true'
		    :columns="columns"
			value-key='pat_name'
		    @cancel="showPicker = false"
		    @confirm="onConfirm"
		  />
		</van-popup>
	</div>
	</van-pull-refresh>
</template>

<script>
	export default {
		data() {
			return {
				isLoading: false,
				scrollTop:0,
				refDisabled:false,
				dataList:[],
				columns:[],
				userInfo:{},
				showPicker:false,
			};
		},
		created() {
			this.petList()
		},
		mounted(){
			let box = this.$refs.pageInfo;
			box.addEventListener('scroll',()=>{
				this.scrollTop = box.scrollTop;
			});
		},
		watch: {
			scrollTop(val){
				if(val==0){
					this.refDisabled=false
				}else{
					this.refDisabled=true
				}
			}
		},
		methods: {
			onRefresh() {
				this.getList()
				setTimeout(() => {
					this.isLoading = false;
				}, 500);
			},
			petList() {
				let that=this
				let url = "/api/pat/list";
				this.$axios.get(url).then(res => {
					that.columns = res.pat_info
					var user={}
					if(that.columns.length>0){
						that.columns.forEach((item, index) => {
							if(item.is_self){
								user=item
							}
						})
					}
					if(!user.id&&that.columns.length>0){
						user=that.columns[0]
					}
					that.userInfo=user
					if(that.userInfo.pid){
						that.getList()
					}
				})
				.catch(err => {
					console.log("err", err);
				});
			},
			getList(){
				let that=this
				let url = "/api/his/get_registers";
				this.$axios.post(url,{
					query_key:'1',
					query_content:that.userInfo.pid,
					charge_type:0,//查已缴费
				}).then(res => {
					console.log(res)
					if(res.rgst_list){
						that.dataList=res.rgst_list
					}else{
						// that.$toast(res.ack_info.err_msg+'！');
						that.dataList=[]
					}
					
				}).catch(err => {
					console.log("err", err);
				});
			},
			onConfirm(e){
				this.showPicker=false
				this.dataList=[]
				this.userInfo=e
				this.getList()
			},
			
			toPageLink(url){
				this.$router.push({
					path:url,
					query:{},
				})
			},
			toNumShow(v){
				if(v.exe_status ==0){//等待接诊
					this.$router.push({
						path:'/registerShow',
						query:{
							showtype:'info',
							rgst_no:v.rgst_no,
							pid:v.pid
						},
					})
				}
			},
			// <!-- "exe_status": "就诊状态|0-等待接诊,1-完成就诊,2-正在就诊,-1标记为不就诊", -->
			// <!-- pay_status": "支付状态|0-待支付;1-已支付;2-已退费", -->
			getStatusText: function(v) {
				if(v.pay_status==0){
					return '待支付'
				}else{
					if (v.exe_status == '0') {
						return '待就诊'
					}else if (v.exe_status == '1') {
						return '已就诊'
					}else if (v.exe_status == '2') {
						return '正在就诊'
					}else if (v.exe_status == '-1'){
						return '已退号'
					}
				}
			},
		}
	};
</script>

<style lang="less" scoped>
	.content{
		min-height: 100vh;
		background-color:#f0f8f8;
		.c_1977FD{color:#1977FD;}
		.noData{
			margin: 95px auto;
			width: 158px;
			text-align: center;
			&-img{
				width: 158px;
				height:160px;
			}
			&-text{
				font-size: 15px;
				font-family: PingFang;
				font-weight: 500;
				color: #333333;
				margin-top: -20px;
			}
		}
		.registerList{
			width: 100%;
			padding-top: 54px;
			&-i{
				margin: 0 auto 10px auto;
				width: 340px;
				height: 100px;
				background: #FFFFFF;
				border-radius: 10px;
				padding:15px 12px;
				font-size: 11px;
				font-family: PingFang;
				font-weight: 500;
				color: #333333;
				&-more{
					width:18px;
					bottom: 20px;
					right: 13px;
				}
				&-t{
					font-size: 11px;
					font-family: PingFang;
					font-weight: 500;
					color: #333333;
					margin-bottom: 15px;
					span{
						margin-left:23px;
					}
				}
				&-btn{
					width: 50px;
					height: 20px;
					background: #1977FD;
					border-radius: 10px;
					font-size: 11px;
					font-family: PingFang;
					font-weight: 500;
					color: #FFFFFF;
					text-align: center;
					line-height: 20px;
				}
				.gary_btn{
					background: #999999;
				}
				&-name{
					font-size: 15px;
					font-family: PingFang;
					font-weight: 500;
					color: #333333;
				}
			}
		}
		.tips{
			position: fixed;
			top: 0;
			padding:0 18px;
			width: 375px;
			height: 44px;
			background: linear-gradient(-90deg, #68E198 0%, #13BAB8 100%);
			font-size: 15px;
			font-family: MiSans;
			font-weight: 500;
			z-index: 99;
			color: #FFFFFF;
			span{
				margin-left: 23px;
			}
			img{
				width: 20px;
			}
		}
	}
</style>